package common.utils;

import lombok.var;

public class ConvertUtil {

    public static Integer[] StringArray2IntegerArray(String[] values) {
        var ints = new Integer[values.length];
        for (int index = 0; index < values.length; index++)
            ints[index] = Integer.parseInt(values[index]);
        return ints;
    }

    public static int toInt(String value) {
        return Integer.parseInt(value);
    }

    public static Long toNullableLong(Object value) {
        if (value == null)
            return null;
        return Long.parseLong(value.toString());
    }

    public static long toLong(Object value) {
        if (value == null)
            return 0;
        return Long.parseLong(value.toString());
    }

    public static String toString(Object value) {
        if (value == null)
            return null;
        return value.toString();
    }

    final static String[] lowerTrueStrings = {"true", "1", "success", "yes",
            "是", "好的", "通过", "成功"};

    public static boolean toBoolean(Object value) {
        var lowerStringValue = value.toString().toLowerCase();
        if (StringUtil.contains(lowerTrueStrings, lowerStringValue))
            return true;
        else
            return Boolean.valueOf(lowerStringValue);
    }

}
